<?php
    include_once 'resize.php';
    class upload{
        function upload_img($file){
            $size=$file['image']['size'];
            if($size>1048576)
            {
                return "error file size > 1 MB";
            }
            else{
                $upload_img = new resize();

                $originalLocation = $file['image']['tmp_name'];


                //resize and upload image to project
                $uploaddir = '../uploads/gallery/';
                $resizeLocation = $uploaddir . basename($file['image']['name']);
                $width = 730;
                $height = 469;
                $result_th = $upload_img->resize_img($width, $height, $resizeLocation, $originalLocation);

                //create thumbnail and upload to thumb
                $uploaddir = '../uploads/thumb/';
                $resizeLocation = $uploaddir . basename($file['image']['name']);
                $width = 145;
                $height = 100;
                $result_re = $upload_img->resize_img($width, $height, $resizeLocation, $originalLocation);

                //upload original image to original_img
                $uploaddir = '../uploads/original_image/';
                $uploadLocation= $uploaddir . basename($file['image']['name']);
                $result_up = move_uploaded_file($originalLocation, $uploadLocation);
                if ($result_re && $uploaddir) {
                    return '';
                } else {
                    $error = "error ".$file['image']['error']." --- ".$file['image']['tmp_name']." %%% ".$file."($size)";
                    return $error;

                }
            }
           
        }
    }
        
?>